﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Diploma.Models;
using DiplomaWeb.Models.Student;

namespace DiplomaWeb.Models.CompaniesAndLecturers
{
    public class CompanyPropertiesViewModel
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public List<CompanyLevelsViewModel> Levels { get; set; }

        public void ToViewMode(Company company)
        {
            Id = company.Id;
            Name = company.DisplayName;
            Levels = DataManager.Instance.QualificationLevelsRepository.GetAllLevels().Select(r => new CompanyLevelsViewModel
                                                                                                  {
                                                                                                      Id = r.QualificationLevelId,
                                                                                                      Name = r.Name
                                                                                                  }).ToList();

            foreach (CompaniesForQualificationLevel item in company.CompaniesForQualificationLevels)
            {
                var level = Levels.First(r => r.Id == item.QualificationLevelId);
                level.IsCheck = true;
                level.MaxStudents = item.MaxSudents;
                level.Students = DataManager.Instance.StudentsRepository.GetStudentsForCompany(item.QualificationLevelId, company.Id).Select(r => new StudentViewModel(r));
            }
        }
    }
}